package org.dei.perla.parser.statements;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import org.dei.perla.parser.expressions.*;

public class SetParametersStatement extends Statement{
	
	private HashMap<String, Constant> pPairAttributeValueMap;
	private ArrayList<ConstantID> pIDs;
	
	public SetParametersStatement(){
		this.pPairAttributeValueMap = new HashMap<String, Constant>();
		this.pIDs = new ArrayList<ConstantID>();
	}
	
	public void addPairAttributeValue(String parAttributeName, Constant parAttributeValue){
		if (!this.pPairAttributeValueMap.containsKey(parAttributeName))
			this.pPairAttributeValueMap.put(parAttributeName, parAttributeValue);
		else
			//TODO: Creare eccezione
			return;
	}
	
	public void addID(ConstantID parID){
		if(!this.pIDs.contains(parID))
			this.pIDs.add(parID);
	}
	
	//Aggiunto da Diego il 7/2/09
	public ArrayList<ConstantID> getIDs() {
		
		return this.pIDs;
	}
	
	//Aggiunto da Diego il 7/2/09
	public HashMap<String,Constant> getAttributesToSet() {
		
		return this.pPairAttributeValueMap;
	}
	
	public String toString() {
		String tStringToReturn = "";
		tStringToReturn += "SET ";
		Iterator<String> tIteratorKeySet;
		Iterator<ConstantID> tIteratorID;
		
		tIteratorKeySet = pPairAttributeValueMap.keySet().iterator();
		
		while(tIteratorKeySet.hasNext()){
			String tName = tIteratorKeySet.next();
			tStringToReturn += tName + " = " + pPairAttributeValueMap.get(tName);
			if (tIteratorKeySet.hasNext())
				tStringToReturn += ", ";
		}
		tStringToReturn += "\n" + "ON ";
		
		tIteratorID = pIDs.iterator();
		
		while(tIteratorID.hasNext()){
			ConstantID tID = tIteratorID.next();
			tStringToReturn += tID;
			if (tIteratorID.hasNext())
				tStringToReturn += ", ";
		}
		
		return tStringToReturn;
	}
	
}
